<?php
require_once('TVB/PWORKS/mvc/FrontController.class.php');
require_once('TVB/PWORKS/mvc/DefaultSystemDataHelper.class.php');
require_once('TVB/PWORKS/mvc/CachedConfigHelper.class.php');
require_once('TVB/PWORKS/common/cache/impl/SimpleCacheHelper.class.php');
require_once('TVB/PWORKS/common/cache/impl/ApcCache.class.php');
require_once('TVB/PWORKS/util/DebugUtil.class.php');

//tvb 
require_once 'TVB/pms/pdes/common/bootstrap.php';

//============================
// Debug codes for developing
//============================
$debug = isset($_REQUEST['__debug'])?$_REQUEST['__debug']:false;
DebugUtil::$enable = $debug; 
$refCache = isset($_REQUEST['__clean_cache'])?$_REQUEST['__clean_cache']:false;
if($refCache) apc_clear_cache('user');

try{

//set config helper
$confHelper = new CachedConfigHelper();
$confCacheHelper = new SimpleCacheHelper();
//$cacheStore = new CacheStore();
$confCacheHelper->setGroup('pdes-app-conf');
$confCacheHelper->setCache(new ApcCache(), 1);
//$cacheStore->setCache(new ApcCache(), 1);
$confHelper->setCacheHelper($confCacheHelper);
//$confHelper->setCacheStore($cacheStore);
$doConfigCheck = false;
$confHelper->init('/data/pms/pdes/conf/pworks/pdes.xml', $doConfigCheck);
//$confHelper->init('/data/pms/pdes/conf/pdes.xml');

FrontController::$confHelper = $confHelper;

//set data input helper
FrontController::$dataHelper = new DefaultSystemDataHelper();

//set cache helper
//$appCacheHelper = new CacheStore();
$appCacheHelper = new SimpleCacheHelper();
$appCacheHelper->setGroup('pdes-app-obj');
$appCacheHelper->setCache(new ApcCache(), 1);
//$appCacheHelper->setCache(new ApcCache(), 1);
//$dataHelper = new DefaultSystemDataHelper();

	//FrontController::init($confHelper, $dataHelper, $appCacheHelper);
	FrontController::$cacheHelper = $appCacheHelper;

	//startup
	FrontController::start();

}catch(SystemException $e){
	//if(__DEBUG__){
	if($debug){
		echo "<h3>SystemException</h3>";
		echo "<B>ID:</B>". $e->id;
		echo "<br>";
		echo "<B>TYPE:</B>". $e->type;
		echo "<br>";
		echo '<B>MESSAGE:</B><font size="4" color="red">'; 
		echo $e->message;
		echo "</font>";
		echo "<br>";     
	}	
}
